#include <ros/ros.h>
#include <test_service_roscpp/mysrv.h>

bool handle_function(test_service_roscpp::mysrv::Request &req, test_service_roscpp::mysrv::Response &res)
{
 ROS_INFO("Request from %s with age %d", req.name.c_str(), req.age);
 //处理请求,结果写入response
 res.feedback = "Hi " + req.name + ". I'm server!";
 //返回true,正确处理了请求
 return true;
}

int main(int argc, char** argv)
{
 ros::init(argc, argv, "server");  //解析参数,命名节点server
 ros::NodeHandle handle;        //创建句柄,实例化node
 ros::ServiceServer service = handle.advertiseService("tangyuaner", handle_function);  
 //写明服务的处理函数
 ros::spin();
 return 0;
}
